package blank

import "reflect"

//异常判断
func InterfaceIsNil1(i interface{}) (ret bool) {
	ret = i == nil

	if !ret { //需要进一步做判断
		defer func() {
			ret = reflect.ValueOf(i).IsZero()
			recover()
		}()
		ret = reflect.ValueOf(i).IsNil() //值类型做异常判断，会panic的
	}

	return
}

//类型判断
func InterfaceIsNil2(i interface{}) bool {
	ret := i == nil

	if !ret { //需要进一步做判断
		vi := reflect.ValueOf(i)
		kind := vi.Kind()
		switch kind {
		case reflect.Slice, reflect.Map, reflect.Chan, reflect.Interface, reflect.Func, reflect.Ptr:
			return vi.IsNil()
		default:
			return vi.IsZero()
		}
	}

	return ret
}
